import {esri} from "../../api/esriAPI";

/**
 * 比例尺
 * @class
 * */
export const ScaleBarUtil = class {
  _viewManage = null;
  _scaleBar = null;

  constructor(viewManage) {
    this._viewManage = viewManage;
  }

  add(position = "bottom-left") {
    let view = this._viewManage.getMapView();
    if (!view) {
      return;
    }
    var scaleBar = new esri.ScaleBar({
      view: view,
      unit: 'metric', //单位km，默认mile
      style: "ruler"
    });
    view.ui.add(scaleBar, {position});
    this._scaleBar = scaleBar;
  }

  /**
   * 移除比例尺
   */
  remove() {
    let view = this._viewManage.getMapView();
    if (!view) {
      return;
    }
    view.ui.remove(this._scaleBar);
  }
}


